package fr.unice.polytech.chord.core;

import java.io.Serializable;
import java.math.BigInteger;

/**
 * A finger is an abstraction of Chord. It can be see like a successor to the
 * power of 2.
 * 
 * @author Anthony Parisy
 * @author Laurent Pellegrino
 * @author Marc Valdener
 * 
 * @version 10/28/2009
 */
@SuppressWarnings("serial")
public class Finger implements Serializable {

	private BigInteger startIndex;

	private ChordNode node;

	public Finger(BigInteger startIndex, ChordNode node) {
		super();
		this.startIndex = startIndex;
		this.node = node;
	}

	/**
	 * Returns the peer to which this finger is associated.
	 * 
	 * @return the peer to which this finger is associated.
	 */
	public ChordNode getNode() {
		return this.node;
	}

	/**
	 * Sets the peer to which this finger is associated.
	 * 
	 * @param node
	 *            the new peer to use.
	 */
	public void setNode(ChordNode node) {
		this.node = node;
	}

	/**
	 * Returns the identifier to which this finger is associated.
	 * 
	 * @return the identifier to which this finger is associated.
	 */
	public BigInteger getStartIndex() {
		return this.startIndex;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		return "Finger[startIndex=" + this.startIndex + ", node=" + this.node
				+ "]";
	}

}
